package net.efo.view;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Observable;
import java.util.Observer;

import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JToolBar;

import net.efo.model.Document;

/**
 * DocumentView is a JPanel which holds all document information, depending on the type of document.
 * 
 * @author Pascal de Vink
 *
 */
public class DocumentView extends JPanel implements Observer,KeyListener {

	private static final long serialVersionUID = 2361551570068225021L;
	private JTextArea jTextArea1;
	private JToolBar jToolBar1;
	private Document doc;
	
	public DocumentView(Document doc) {
		this.doc = doc;
		this.doc.addObserver(this);
		
		BoxLayout jPanel1Layout = new BoxLayout(this, javax.swing.BoxLayout.Y_AXIS);
		this.setLayout(jPanel1Layout);
		{
			jToolBar1 = new JToolBar();
			jToolBar1.setPreferredSize(new java.awt.Dimension(25, 20));
			this.add(jToolBar1);
		}
		{
			jTextArea1 = new JTextArea();
			jTextArea1.addKeyListener(this);
			this.add(jTextArea1);
			jTextArea1.setText((String)this.doc.getContents());
		}
	}
	
	public void update(Observable o, Object arg) {
		Document doc = (Document)o;
		this.jTextArea1.setText((String)this.doc.getContents());
	}

	public void keyPressed(KeyEvent arg0) {
		if (arg0.isControlDown()) {
			if (arg0.getKeyCode() == 83) {
				this.doc.setContents(this.jTextArea1.getText() + " blaaat");
			}
		}
	}

	public void keyReleased(KeyEvent arg0) {}
	public void keyTyped(KeyEvent arg0) {}	
}
